//
// Created by guanyicheng on 2022/5/7.
//

#include "../../common.h"

class Solution {
public:
    string removeDuplicates(string s) {
        auto _stack = stack<char>{};
        for(char c: s) {
            if (!_stack.empty() && _stack.top() == c) {
                _stack.pop();
            }else {
                _stack.emplace(c);
            }
        }
        s.resize(_stack.size());
        for(int i = s.size() - 1; i > -1; --i) {
            s[i] = _stack.top();
            _stack.pop();
        }
        return s;
    }
};

int main() {
    cout << Solution().removeDuplicates("abbaca") << endl;
}